package com.stylefeng.guns.rest.modular.message.controller;

import com.stylefeng.guns.rest.common.CommonResponse;
import com.stylefeng.guns.rest.common.exception.BizExceptionEnum;
import com.stylefeng.guns.rest.common.exception.BussinessException;
import com.stylefeng.guns.rest.modular.attent.controller.dto.AttentHotRequest;
import com.stylefeng.guns.rest.modular.jubao.controller.dto.JubaoRequest;
import com.stylefeng.guns.rest.modular.jubao.service.JubaoService;
import com.stylefeng.guns.rest.modular.message.service.MessageService;
import org.apache.commons.logging.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by ASUS-PC on 2018/6/26.
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    private final Log logger = org.apache.commons.logging.LogFactory.getLog(this.getClass());

    @Autowired
    MessageService messageService;

    //获取系统通知消息
    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    public ResponseEntity<?> getMessageList(@RequestBody AttentHotRequest request) {
        if(request.getUserId()==0){
            throw new BussinessException(BizExceptionEnum.NEED_PARAMS);
        }
        if (request.getPage() == 0) {
            request.setPage(1);
        }
        if (request.getSize() == 0) {
            request.setSize(20);
        }
        return ResponseEntity.ok(CommonResponse.ok(messageService.getMessageList(request)));

    }
}
